package com.vitabuybuy.tv.ui.mine.order.adapter

import android.view.View
import android.widget.ImageView
import androidx.core.content.ContextCompat
import com.library.common.widget.RoundImageView
import com.vitabuybuy.tv.R
import com.vitabuybuy.tv.adaptebinding.ImageAdapter
import com.library.common.base.MBaseRecycAdapter

/**
 * 作者：SimGa
 * 日期：2019/5/24
 * 时间：15:29
 * 包名：com.seefun.app.ui.mine.adapter
 */
class PictureAdapter(picNum: Int) : MBaseRecycAdapter<String>() {
    override fun normalViewId(): Int {
        return R.layout.item_pic
    }

    var picNum: Int = picNum
    override fun getItemCount(): Int {
        if (mData.size == picNum) {
            return mData.size
        }
        return mData.size + 1
    }

    override fun onHolder(holder: ViewHolder, position: Int) {
        if (position == mData.size) {
            holder.getView<ImageView>(R.id.iv_delete)?.visibility = View.GONE
            holder.getView<RoundImageView>(R.id.iv_)?.setImageResource(R.drawable.add_image)
        } else {
            holder.getView<ImageView>(R.id.iv_delete)?.visibility = View.VISIBLE
            ImageAdapter.setNomalImageUrl(
                holder.getView<ImageView>(R.id.iv_)!!, mData[position],
                ContextCompat.getDrawable(mContext!!, R.drawable.default_image)
            )
        }
        holder.getView<ImageView>(R.id.iv_delete)?.setOnClickListener {
            if (lisetener != null)
                lisetener?.invoke(position)
        }
    }

    var lisetener: ((position: Int) -> Unit)? = null

    fun setOnClickDeleteListener(lisetener: ((position: Int) -> Unit)) {
        this.lisetener = lisetener
    }
}
